//
//  MapCreator.cpp
//  ballvsblock
//
//  Created by 宋志京 on 2017/6/15.
//
//

#include "MapCreator.h"
#include "GameScene.h"
#include "Block.h"
#include "Ball.h"
#include "Reward.h"

USING_NS_CC;
MapCreator* MapCreator::createWithGameScene(GameScene *gs){
    MapCreator *mc = new MapCreator();
    if (mc && mc->initWithGameScene(gs)) {
        mc->autorelease();
        return mc;
    }else{
        delete mc;
        mc = NULL;
        return NULL;
    }
}
bool MapCreator::initWithGameScene(GameScene *gs){
    if (!Node::init()){
        return false;
    }
    this->gs=gs;
    this->schedule(CC_SCHEDULE_SELECTOR(MapCreator::createUpdate), 2.0f);
    return true;
}

void MapCreator::createUpdate(float dt){
    Block *b = Block::create();
    b->setNum(CCRANDOM_0_1()*30+1);
    b->setName("Block");
    int x=CCRANDOM_0_1()*5;
    b->setPosition(b->getBlockWidth()*(.5+x),gs->ball->getPositionY()+1500);
    gs->bg->addChild(b);
    
    Reward *r = Reward::create();
    r->setNum(CCRANDOM_0_1()*30+1);
    r->setName("Reward");
    x=CCRANDOM_0_1()*5;
    r->setPosition(r->getRewardWidth()*(.5+x),gs->ball->getPositionY()+1200);
    gs->bg->addChild(r);
}
